/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CONTROLLER;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 *
 * @author Irene and Morten
 */


public class Persister {


    /* Is in charge of saving the objects and strings created in the code.
     * @param o is the object created
     * @param filename is the filename of the file.
     */
    public void save(Object o, String fileName) {
    FileOutputStream fos = null;
    ObjectOutputStream oos = null;
        try {
            fos = new FileOutputStream(fileName);
            oos = new ObjectOutputStream(fos);
            oos.writeObject(o);
            oos.close();
            fos.close();

        } catch (IOException ex) {
            ex.printStackTrace();
        }
}

    /*Is in charge of loading the files into our PIM-view again
     * @param filename is the filename it gets from the harddrive
     * @return o is the returned file.
     */
public Object load(String filename){
    FileInputStream fis = null;
    ObjectInputStream ois = null;
    Object o = null;
    try{
        fis = new FileInputStream(filename);
        ois = new ObjectInputStream(fis);
        o = ois.readObject();
        ois.close();
        fis.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    }
    return o;
}
}
